package com.ruoyi.ice.controller;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.ice.core.Ice;
import com.ice.core.context.IcePack;
import com.ice.core.context.IceRoam;
import com.ice.core.utils.JacksonUtils;
import com.ruoyi.base.service.ISSerialService;
import com.ruoyi.common.core.domain.AjaxResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;

/**
 * @author waitmoon
 */
@Slf4j
@RestController
@RequestMapping("/ice-test")
public class IceTestController {

    @RequestMapping(value = "/test", method = RequestMethod.POST)
    public String test(@RequestBody Map<String, Object> map) throws JsonProcessingException {
        IcePack pack = JacksonUtils.readJson(JacksonUtils.toJsonString(map), IcePack.class);
        return JacksonUtils.toJsonString(Ice.processCtx(pack));
    }

    @RequestMapping(value = "/recharge", method = RequestMethod.GET)
    public String recharge(@RequestParam Integer cost, @RequestParam Integer uid) {
        IcePack pack = new IcePack();
        pack.setScene("recharge");
        IceRoam roam = new IceRoam();
        roam.put("cost", cost);
        roam.put("uid", uid);
        pack.setRoam(roam);
        Ice.syncProcess(pack);
        return JacksonUtils.toJsonString(roam.get("result"));
    }

    @RequestMapping(value = "/consume", method = RequestMethod.GET)
    public String consume(@RequestParam Integer cost, @RequestParam Integer uid) {
        IcePack pack = new IcePack();
        pack.setScene("consume");
        IceRoam roam = new IceRoam();
        roam.put("cost", cost);
        roam.put("uid", uid);
        pack.setRoam(roam);
        Ice.syncProcess(pack);
        return JacksonUtils.toJsonString(roam.get("result"));
    }

    @RequestMapping("/testBerth")
    public String testBerth(String shipWeight,String cntrNum, String teu,String berthTime ) throws JsonProcessingException {




        IcePack pack = new IcePack();

        pack.setIceId(20L);



        IceRoam roam = new IceRoam();

        roam.put("停泊时间-取整",berthTime);
        roam.put("船舶净吨",shipWeight);
        roam.put("箱数",cntrNum);
        roam.put("TEU",teu);
        roam.put("固定费用","1");
        roam.put("停泊时间",".147");

        pack.setRoam(roam);

        IceRoam result = Ice.processSingleRoam(pack);

        System.out.println(result);

        return JacksonUtils.toJsonString(result);

    }

    @Autowired
    ISSerialService serialService;

    @RequestMapping("/testSerial")
    public AjaxResult getSerial(String code,String companyCod){
        return AjaxResult.success(serialService.getSerialNumberByCodeDept(code,companyCod));
    }

}
